package response

import (
  "livefind/model/evidences"
  "livefind/utils"
)

type EvidenceListRsp struct {
  List     []EvidenceInfoRsp `json:"list"`
  Page     int               `json:"page"`
  PageSize int               `json:"pageSize"`
  Total    int               `json:"total"`
}
type EvidenceInfoRsp struct {
  ID           string `json:"id,omitempty"`
  CaseID       string `json:"caseId,omitempty"`
  EvidenceNo   string `json:"evidenceNo,omitempty"`
  EvidenceName string `json:"evidenceName,omitempty"`
  EvidenceType string `json:"evidenceType,omitempty"`
  OriginalPath string `json:"originalPath,omitempty"`
  SavePath     string `json:"savePath,omitempty"`
}

type UploadInfoRsp struct {
  Path     string `json:"path,omitempty"`
  FileName string `json:"fileName,omitempty"`
}

type EvidenceGetRsp struct {
  EvidenceInfoRsp
}

func ConvertCreate2Rsp() {

}

func ConvertList2Rsp(evidencesInfo []evidences.EvidenceInfo, page, pageSize int, totalNum int64) EvidenceListRsp {
  if page < 1 {
    page = 1
  }
  if pageSize < 1 {
    pageSize = 10
  }
  if evidencesInfo == nil {
    evidencesInfo = []evidences.EvidenceInfo{}
  }
  var infos []EvidenceInfoRsp
  infos = make([]EvidenceInfoRsp, 0, len(evidencesInfo))
  var evidenceInfoRsp EvidenceInfoRsp
  var info evidences.EvidenceInfo
  for _, info = range evidencesInfo {
    utils.StructAssign(&evidenceInfoRsp, &info)
    evidenceInfoRsp.ID = info.ID.Hex()
    evidenceInfoRsp.CaseID = info.CaseID.Hex()
    infos = append(infos, evidenceInfoRsp)
  }
  return EvidenceListRsp{
    List:     infos,
    Page:     page,
    PageSize: pageSize,
    Total:    int(totalNum),
  }
}

func ConvertGetById2Rsp(evidenceInfo evidences.EvidenceInfo) EvidenceGetRsp {
  return EvidenceGetRsp{
    EvidenceInfoRsp{
      ID:           evidenceInfo.ID.Hex(),
      CaseID:       evidenceInfo.CaseID.Hex(),
      EvidenceNo:   evidenceInfo.EvidenceNo,
      EvidenceName: evidenceInfo.EvidenceName,
      EvidenceType: evidenceInfo.EvidenceType,
      OriginalPath: evidenceInfo.OriginalPath,
      SavePath:     evidenceInfo.SavePath,
    },
  }
}

func ConvertUpload2Rsp(path, fileName string) *UploadInfoRsp {
  return &UploadInfoRsp{
    Path:     path,
    FileName: fileName,
  }
}
